package com.lyj.book.common.bean;

import com.lyj.book.common.enums.ResponseCodeEnum;
import lombok.Data;

import java.io.Serializable;

/**
 * @author liuyj
 * @create 2018-01-31 13:45
 **/
@Data
public class Response<T> implements Serializable{

    private static final long serialVersionUID = 1L;

    private int status;

    private String message;

    private T data;

    private static final String SUCCESS = "success";

    private static final String ERROR = "ERROR";

    public Response success(){
        this.status = ResponseCodeEnum.SUCCESS.getCode();
        this.message = SUCCESS;
        return this;
    }

    public Response success(T data){
        this.success();
        this.data=data;
        return this;
    }


    public Response failure(){
        this.status=ResponseCodeEnum.FAIL.getCode();
        this.message = ERROR;
        return this;
    }

    public Response failure(String message){
        this.failure();
        this.message = message;
        return this;
    }


    public Response result(int status){
        this.status = status;
        return this;
    }

    public Response result(int status,String message){
        this.result(status);
        this.message =message;
        return this;
    }

    public Response result(int status,T data){
        this.result(status);
        this.data =data;
        return this;
    }

    public Response result(int status,String message,T data){
        this.result(status,message);
        this.data =data;
        return this;
    }

}
